Skip to content

perf(android): [SDK Overhead Reduction 3] Reuse SentryExecutorService for DeviceInfoUtil pre-caching#5502

Draft
adinauer wants to merge 1 commit into
perf/sdk-overhead-reductionfrom
perf/sdk-overhead-reduction-reuse-executor
Draft

perf(android): [SDK Overhead Reduction 3] Reuse SentryExecutorService for DeviceInfoUtil pre-caching#5502
adinauer wants to merge 1 commit into
perf/sdk-overhead-reductionfrom
perf/sdk-overhead-reduction-reuse-executor

Conversation

@adinauer

@adinauer adinauer commented Jun 5, 2026

Copy link
Copy Markdown
Member

PR Stack (SDK Overhead Reduction)


📜 Description

Replace Executors.newSingleThreadExecutor() with options.getExecutorService() in DefaultAndroidEventProcessor for the DeviceInfoUtil pre-caching task. This avoids creating a dedicated thread + executor during SDK init when the SDK already has an executor service available. Also removes the executorService.shutdown() call since we don't own the shared executor.

💡 Motivation and Context

Part of the SDK Overhead Reduction stack. During Android SDK init, DefaultAndroidEventProcessor was creating its own SingleThreadExecutor just to submit one task for pre-caching device info. The SDK's executor service (SentryExecutorService) is already available at this point and can handle this work without the overhead of spinning up an additional thread pool.

💚 How did you test it?

  • ./gradlew :sentry-android-core:compileDebugUnitTestJavaWithJavac — compiles successfully
  • ./gradlew spotlessApply apiDump — no API surface changes

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

More SDK overhead reduction PRs in this stack.

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

#skip-changelog

…hing

Replace Executors.newSingleThreadExecutor() with
options.getExecutorService() in DefaultAndroidEventProcessor to avoid
creating a dedicated thread during init. The SDK already has an executor
service available.
@sentry

sentry Bot commented Jun 5, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.43.1 (1) release

⚙️ sentry-android Build Distribution Settings

@adinauer

adinauer commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

Turns out this is actually slowing down init.
The question is, do we still want to update this to avoid creating a new short lived thread?

Screenshot 2026-06-08 at 16 36 00

@romtsn

romtsn commented Jun 8, 2026

Copy link
Copy Markdown
Member

the change looks good to me (still would prefer not to spawn threads when unnecessary), but i'd be curious where the slowness comes from. Could you check the actual flamegraph in perfetto?

@adinauer

Copy link
Copy Markdown
Member Author

Could you check the actual flamegraph in perfetto?

Will do, likely tomorrow.

@adinauer

Copy link
Copy Markdown
Member Author

@romtsn I just checked the perfetto traces and it basically sums up to:
while this avoids creating a short lived thread it adds work to the single threaded shared SentryExecutorService on SentryOptions and causes other queued startup work to be delayed

Depending on the device and its load this might add a significant chunk to startup. Maybe loading this lazily is an option, I'll investigate a bit more.

@adinauer

Copy link
Copy Markdown
Member Author

A quick investigation suggests we'd be running the risk of ANRs when doing this work lazily on first use since it might run on main thread then.

I still wanted to investigate whether we could add async event processing. This would be a good candidate to move but might also be a breaking change for customers who expect the info to already be present when their callbacks kick in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants